package classloader;

/**
 * 类加载器  热部署
 *
 * @author dingwen
 * @date 2021/08/29
 */
public class ClassLoaderDemo6 {
    public static void main(String[] args) throws Exception {
//        MyFileClassLoader myFileClassLoader1 = new MyFileClassLoader("/Users/dingwen/Documents/study/java8-study/src/");
//        MyFileClassLoader myFileClassLoader2 = new MyFileClassLoader(myFileClassLoader1,"/Users/dingwen/Documents/study/java8-study/src/");
//        Class<?> clazz1 = myFileClassLoader1.findClass("classloader.URLClassLoaderDemo");
//        Class<?> clazz2 = myFileClassLoader2.findClass("classloader.URLClassLoaderDemo");

        // hash code 不相等
//        System.out.println("clazz1.hashCode() = " + clazz1.hashCode());
//        System.out.println("clazz2.hashCode() = " + clazz2.hashCode());



        // 执行类双亲委派模式
        MyFileClassLoader myFileClassLoader1 = new MyFileClassLoader("/Users/dingwen/Documents/study/java8-study/src/");
        MyFileClassLoader myFileClassLoader2 = new MyFileClassLoader(myFileClassLoader1,"/Users/dingwen/Documents/study/java8-study/src/");
        Class<?> clazz1 = myFileClassLoader1.loadClass("classloader.URLClassLoaderDemo");
        Class<?> clazz2 = myFileClassLoader2.loadClass("classloader.URLClassLoaderDemo");

        // hash code 相等
        System.out.println("clazz1.hashCode() = " + clazz1.hashCode());
        System.out.println("clazz2.hashCode() = " + clazz2.hashCode());
    }
}
